/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package swap;

import Programas.Processo;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 *
 * @author modesto
 */
public class Swap {

    private HashMap processos;

    public Swap() {
        this.processos = new HashMap();
    }

    public void ps() {
        Iterator it = this.processos.entrySet().iterator();
        ProcessoEmSwap processo_em_swap;
        Processo processo;

        while (it.hasNext()) {
            Map.Entry pairs = (Map.Entry) it.next();

            processo_em_swap = (ProcessoEmSwap) pairs.getValue();

            processo = processo_em_swap.processo;

            System.out.println("s: \t" + processo.getIdProcesso() + "\t" + processo.getGroupId() + "\t" + processo.getEstado() + "\t" + processo.getTamanho());
        }
    }

    public void putProcesso(int pid, ProcessoEmSwap processo) {
        processos.put(pid, processo);
    }

    public ProcessoEmSwap getProcesso(int pid) {
        return (ProcessoEmSwap) this.processos.remove(pid);
    }
    
    public ProcessoEmSwap getProcessoByGrupo(int gid)
    {
        Iterator it = this.processos.entrySet().iterator();
        Processo processo;
        
        while (it.hasNext())
        {
            Map.Entry pairs = (Map.Entry)it.next();
            
            processo = ((ProcessoEmSwap)pairs.getValue()).processo;
            
            if (processo.getGroupId() == gid)
                return (ProcessoEmSwap)this.processos.remove(pairs.getKey());
        }
        
        return null;
    }

}
